package com.gitee.xcfyl.simplehttpserver.io;

import java.io.OutputStream;

/**
 * 封装了Http响应
 *
 * @author 西城风雨楼
 */
public class HttpResponse {
    private final OutputStream out;

    public HttpResponse(OutputStream out) {
        this.out = out;
    }

    /**
     * 向客户端返回消息
     *
     * @param msg 返回的消息
     * @throws Exception 可能会发生异常
     */
    public void write(String msg) throws Exception {
        String sb = "HTTP/1.1 200 OK\n" +
                "Content-Type: text/html;\n" +
                "\r\n" +
                msg;
        out.write(sb.getBytes());
    }
}
